package com.kun.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.kun.service.ActivityService;
import com.kun.service.BookService;
import com.kun.service.UserService;

/**
 * @description: 
 * @author: KM
 * 2018年5月2日 下午11:06:58
 */
@Controller
public class IndexController {
	
	
	@Autowired
	private ActivityService activityService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private BookService bookService;
	
	
	@RequestMapping({"/","/index"})
	public String index(){
		return "index";
	}
	
	@RequestMapping("/book_detail")
    public String book_detail(){
        return "/book_detail";
    } 
	
	@RequestMapping("/sort")
    public String sort(){
        return "/sort";
    } 
	
	@RequestMapping("/wish")
    public String wish(){
        return "/wish";
    } 
	
	
	//生成静态页面的模板
	/**
	 * 首页静态化活动
	 * */
	@RequestMapping("/gActivity")
	public String getActivity(Model model){
		String jsonString = "{issueTime:'desc'}";
		Map<String, Object> map  = activityService.selectActivityTiltle(1, 5, jsonString, false);
		model.addAttribute("activityList", map.get("activityList"));
		return "generation/activity";
	}
	
	/**
	 * 首页静态化共享排行
	 * */
	@RequestMapping("/gShareRank")
	public String getShareRank(Model model){
		String jsonString = "{level:'desc'}";
		Map<String, Object> map  = userService.selectAllUser(1, 5, jsonString, false);
		model.addAttribute("userList", map.get("userList"));
		return "generation/shareRank";
	}
	
	/**
	 * 首页静态化借阅排行
	 * */
	@RequestMapping("/gBorrowRank")
	public String getBorrowRank(Model model){
		String jsonString = "{borrow:'desc'}";
		Map<String, Object> map  = bookService.selectAllBook(1, 5, jsonString, false);
		model.addAttribute("bookList", map.get("bookList"));
		return "generation/borrowRank";
	}

}
